function Slide(options) {
	this.width = options.width;
	this.time = options.time;
	this.now = 0;
	this.ul = null;
	this.list = null;
	this.prev = null;
	this.next = null;
	this.liNum = 0;
	this.timer = null;
}

Slide.prototype.atCalc = function() {
	if (this.now == this.liNum - 1) {
		this.ul.children().eq(0).css({
			'left': this.width + 'px',
			'z-index': 10
		});
		this.ul.children().eq(this.now - 1).css({
			'left': -this.width + 'px',
			'z-index': 10
		});
	} else if (this.now == 0) {
		this.ul.children().eq(this.now + 1).css({
			'left': this.width + 'px',
			'z-index': 10
		});
		this.ul.children().eq(this.liNum - 1).css({
			'left': -this.width + 'px',
			'z-index': 10
		});
	} else {
		this.ul.children().eq(this.now + 1).css({
			'left': this.width + 'px',
			'z-index': 10
		});
		this.ul.children().eq(this.now - 1).css({
			'left': -this.width + 'px',
			'z-index': 10
		});
	}
};
Slide.prototype.mtCalcR = function() {
	this.ul.children().eq(this.now).css({
		'left': this.width + 'px',
		'z-index': 10
	});
};
Slide.prototype.mtCalcL = function() {
	this.ul.children().eq(this.now).css({
		'left': -this.width + 'px',
		'z-index': 10
	});
};
Slide.prototype.move = function() {
	var This = this;
	var lock = true;

	function goRight() {
		if (lock) {
			lock = false;
			if (This.now == This.liNum - 1) {
				This.ul.children().eq(This.now).stop().animate({
					'left': -This.width
				}, 600, 'easeOutBounce');
				This.ul.children().eq(0).stop().animate({
					'left': 0
				}, 600, 'easeOutBounce', function() {
					This.now = 0;
					This.list.children().eq(This.now).addClass('active').siblings().removeClass('active');
					This.atCalc();
					lock = true;
				});
			} else {
				This.ul.children().eq(This.now).stop().animate({
					'left': -This.width
				}, 600, 'easeOutBounce');
				This.ul.children().eq(This.now + 1).stop().animate({
					'left': 0
				}, 600, 'easeOutBounce', function() {
					This.now++;
					This.list.children().eq(This.now).addClass('active').siblings().removeClass('active');
					This.atCalc();
					lock = true;
				});
			}
		}
	}

	function goLeft() {
		if (lock) {
			lock = false;
			if (This.now == 0) {
				This.ul.children().eq(This.now).stop().animate({
					'left': This.width
				}, 300);
				This.ul.children().eq(This.liNum - 1).stop().animate({
					'left': 0
				}, 300, function() {
					This.now = This.liNum - 1;
					This.list.children().eq(This.liNum - 1).addClass('active').siblings().removeClass('active');
					This.atCalc();
					lock = true;
				});
			} else {
				This.ul.children().eq(This.now).stop().animate({
					'left': This.width
				}, 300);
				This.ul.children().eq(This.now - 1).stop().animate({
					'left': 0
				}, 300, function() {
					This.now--;
					This.list.children().eq(This.now).addClass('active').siblings().removeClass('active');
					This.atCalc();
					lock = true;
				});
			}
		}
	}
	this.timer = setInterval(goRight, this.time);
	this.list.children().mouseover(function() {
		var old = This.now;
		var touch = This.list.children().index(this);
		This.now = touch;
		if (touch > old) {
			lock = false;
			This.mtCalcR();
			This.ul.children().eq(old).stop().animate({
				'left': -This.width
			}, 300);
			This.list.children().eq(touch).addClass('active').siblings().removeClass('active');
			This.ul.children().eq(touch).stop().animate({
				'left': 0
			}, 300, function() {
				This.atCalc();
				lock = true;
			});
		} else if (touch < old) {
			lock = false;
			This.mtCalcL();
			This.ul.children().eq(old).stop().animate({
				'left': This.width
			}, 300);
			This.list.children().eq(touch).addClass('active').siblings().removeClass('active');
			This.ul.children().eq(touch).stop().animate({
				'left': 0
			}, 300, function() {
				This.atCalc();
				lock = true;
			});
		}
	});
	this.ul.parent().hover(function() {
		clearInterval(This.timer);
		// $(this).children('a').fadeIn();
	}, function() {
		This.timer = setInterval(goRight, This.time);
		// $(this).children('a').hide();
	});
	// this.next.click(function() {
	// 	goRight();
	// });
	// this.prev.click(function() {
	// 	goLeft();
	// });

};
Slide.prototype.init = function(settings) {
	this.ul = $(settings.ulName);
	this.list = $(settings.listName);
	this.prev = $(settings.prev);
	this.next = $(settings.next);
	this.liNum = this.ul.children().length;
	this.atCalc();
	this.move();
};
var slide = new Slide({
	'width': 778,
	'time': 4000
});